package com.example.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.NestedScrollingParent2;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.adapter.RvAdapter;
import com.example.studyapplication.R;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class CustomNestPartent extends FrameLayout implements NestedScrollingParent2 {

    private View view;
    private RecyclerView mRvFunction;
    private RvAdapter rvAdapter;
    private Context mContext;

    public CustomNestPartent(Context context) {
        super(context);
        this.mContext = context;
    }

    public CustomNestPartent(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        view = View.inflate(context, R.layout.activity_main, this);
        initView();
        initData();
    }

    private void initData() {
        mRvFunction.setLayoutManager(new LinearLayoutManager(mContext));
        rvAdapter = new RvAdapter(mContext, getData());
        mRvFunction.setAdapter(rvAdapter);
    }


    private List<String> getData() {
        List<String> rvData = new ArrayList<>();
        for(int i=0;i<40;i++){
            rvData.add("缓存复用111111--" + i);
        }
        return rvData;
    }

    private void initView() {
        mRvFunction = findViewById(R.id.rv_function);
    }

    public CustomNestPartent(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onStartNestedScroll(@NonNull @NotNull View child, @NonNull @NotNull View target, int axes, int type) {
        return false;
    }

    @Override
    public void onNestedScrollAccepted(@NonNull @NotNull View child, @NonNull @NotNull View target, int axes, int type) {

    }

    @Override
    public void onStopNestedScroll(@NonNull @NotNull View target, int type) {

    }

    @Override
    public void onNestedScroll(@NonNull @NotNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {

    }

    @Override
    public void onNestedPreScroll(@NonNull @NotNull View target, int dx, int dy, @NonNull @NotNull int[] consumed, int type) {

    }
}
